package com.cy.bus.ui;

import com.cy.utils.SysParam;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.support.v4.app.Fragment;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

/**
 * 被其他Fragment继承
 * @author CY
 *
 */
public class WebViewFragment extends Fragment {

	private WebView webView;
	
	public WebView getWebView() {
		return webView;
	}

	public void setWebView(WebView webView) {
		this.webView = webView;
	}

	/**
	 * 初始化WebView
	 */
	@SuppressLint("SetJavaScriptEnabled")
	protected void initWebView(String uri) {
		//支持JavaScript
		webView.getSettings().setJavaScriptEnabled(true);
		webView.loadUrl(SysParam.read("host")+uri);
		webView.setWebViewClient(new WebViewClient(){
			@Override
			public boolean shouldOverrideUrlLoading(WebView view, String url) {
				Intent intent = new Intent(WebViewFragment.this.getActivity(),WebActivity.class);
				intent.putExtra("url", url);
				WebViewFragment.this.startActivity(intent);
				return true;
			}
			
		});
		// 优先使用缓存
		webView.getSettings().setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
	}
}
